

#ifndef PRIORITYMEMORYTABLE_H_
#define PRIORITYMEMORYTABLE_H_


#include "../../Packets/BackSubPkt.h"
#include "../../Packets/PubPkt.h"
#include "../../Common/TimeMs.h"
#include <boost/unordered_map.hpp>
#include <string>
#include <queue>
#include "../../Memory/MemoryWrapper.h"
#include <iostream>
#include "MemoryTable.h"
#include "../../Common/Consts.h"


class PriorityMemoryTable : public MemoryTable {

public:

	PriorityMemoryTable(int parNumMaxSlot, MemoryWrapper* parMemory);

	virtual ~PriorityMemoryTable();

	void updateTable(std::string type, int subscriptionCount, float window, bool resettable, int eventCount);

	void resetTable();

	void fixTable() { }

	void computeInsertion(PubPkt *pkt, std::string complexType);

	/*std::set<PubPkt*>*/ void computeExtraction(BackSubPkt *pkt, std::set<PubPkt*> &resultSet);

private:

	typedef struct PriorityTableStruct {
		float window;
		int count;
		bool resettable;
	} PriorityTable;

	boost::unordered_map<std::string, PriorityTable> parameterTable;
	boost::unordered_map<std::string, std::priority_queue<std::pair<timestamp_t, key_t>, std::vector<std::pair<timestamp_t, key_t> >, Comparison > > clustersMap;

	boost::unordered_map<std::string, PriorityTable> oldParameterTable;
	boost::unordered_map<std::string, std::priority_queue<std::pair<timestamp_t, key_t>, std::vector<std::pair<timestamp_t, key_t> >, Comparison > > oldClustersMap;

	int numMaxSlot;
	int numUsedSlot;
	int keyCounter;
	MemoryWrapper *memory;

	Timer *timer;
};


#endif /* PRIORITYMEMORYTABLE_H_ */
